

import junit.framework.TestCase;

public class TestSingleton extends TestCase {
	public void testSingleton() {
		FileSystem fs = DiskFileSystem.getInstance();
		FileSystem fs2 = DiskFileSystem.getInstance();
		fs.delete(1);
		fs2.delete(2);
		assertSame(fs, fs2);//same
	}

	static class FileSystem {
		public void delete(int i) {
			System.out.println("has delete " + i);
		}
	}

	static class DiskFileSystem extends FileSystem {
		private static DiskFileSystem instance = new DiskFileSystem();

		public static FileSystem getInstance() {
			return instance;
		}
	}
}
